<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Models\TypesAds;
use App\Types;

//使用类
use App\Http\Controllers\Controller;

//后台分类广告控制器
class TypesAdsController extends Controller
{
    //分类广告首页
    public function index(Request $request){
        //多表查询
      $data = TypesAds::join("types","types.id","=","typesads.cid")->select("typesads.*","types.name")->paginate(10);
    //dd($data);


        //加载页面
        return view("admin.sys.types.index")->with("data",$data);
    }

    //分类广告添加页面
    public function create(){
        $data = Types::where("pid",0)->get();

        //加载页面
        return view("admin.sys.types.add")->with('data',$data);
    }

    //分类广告的处理方法
    public function store(Request $request){
       //剔除不需要的数据
        $arr=$request->except("_token");
        //插入数据库
        if(TypesAds::insert($arr)){
            return redirect("admin/sys/types")->with('status', '成功!!!');
        }else{
            return back();
        }

    }


	
}
